<?php
header("Content-type:text/html; charset=utf-8");
require_once ('include/conn.php');
require_once ('system.class.php');
/*用于栏目模板页*/
function channel($args, $content, &$smarty){
	$channel_id=$args['channel_id'];

	/*用于判断是否转向404页面*/
	$arr['error_page']='false';
	$arr['error_page_url']=CIE."/404.php";

	$sql_get_channel_infor="select channel_name,channel_visit_path,is_bottom from channel where channel_id=$channel_id";
	$result_get_channel_infor=mysql_query($sql_get_channel_infor);
	$num=@mysql_num_rows($result_get_channel_infor);
	if($num==0){
		$arr['error_page']='true';
		$smarty->assign("channelinfo",$arr);
		return $content;
	}
	$row_get_channel_infor=mysql_fetch_row($result_get_channel_infor);
	$arr['url']=CIE;
	$arr['channel_name']="首页";
	if ($row_get_channel_infor[2]==0){
		$arr['channel_id']=$channel_id;
		$arr['channel_name']=$row_get_channel_infor[0];
		$arr['url']=CIE."/channel.php?channel_id=$channel_id";
		

		$sql_get_child_channel_infor="select channel_id,channel_name,channel_visit_path from channel where pre_id=$channel_id";
		$result_get_child_channel_infor=mysql_query($sql_get_child_channel_infor);
		while($row_get_child_channel_infor=mysql_fetch_row($result_get_child_channel_infor)){
			$child_id=$row_get_child_channel_infor[0];
			$tmp[$child_id]['channel_id']=$child_id;
			$tmp[$child_id]['channel_name']=$row_get_child_channel_infor[1];
			$tmp[$child_id]['url']=CIE."/channel.php?channel_id=$child_id";
		}
		if(empty($tmp)){
			$tmp=null;
		}
		$arr['child_channel_infor']=$tmp;
		$tmp=array();
	}
	else{
		$sql_get_pre_channel_id="select pre_id from channel where channel_id=$channel_id";
		$result_get_pre_channel_id=mysql_query($sql_get_pre_channel_id);
		$row_get_pre_channel_id=mysql_fetch_row($result_get_pre_channel_id);
		$pre_id=$row_get_pre_channel_id[0];
		if($pre_id==0){
			$tmp['child_id']['channel_id']=$channel_id;
			$tmp['child_id']['channel_name']=$row_get_channel_infor[0];
			$tmp['child_id']['url']=CIE."/channel.php?channel_id=$channel_id";
		}
		else{
			$sql_get_pre_channel_infor="select channel_name,channel_visit_path,is_bottom from channel where channel_id=$pre_id";
			$result_get_pre_channel_infor=mysql_query($sql_get_pre_channel_infor);
			$row_get_pre_channel_infor=mysql_fetch_row($result_get_pre_channel_infor);
			$arr['channel_id']=$pre_id;
			$arr['channel_name']=$row_get_pre_channel_infor[0];
			$arr['url']=CIE."/channel.php?channel_id=$pre_id";
			$sql_get_child_channel_infor="select channel_id,channel_name,channel_visit_path from channel where pre_id=$pre_id";
			$result_get_child_channel_infor=mysql_query($sql_get_child_channel_infor);
			while($row_get_child_channel_infor=mysql_fetch_row($result_get_child_channel_infor)){
				$child_id=$row_get_child_channel_infor[0];
				$tmp[$child_id]['channel_id']=$child_id;
				$tmp[$child_id]['channel_name']=$row_get_child_channel_infor[1];
				$tmp[$child_id]['url']=CIE."/channel.php?channel_id=$child_id";
			}
		}
		if(empty($tmp)){
			$tmp=null;
		}
		$arr['child_channel_infor']=$tmp;
		$tmp=array();
	}

	if(empty($arr)){
		$arr=null;
	}
	$smarty->assign("channelinfo",$arr);
	//print_r($arr);
	return $content;
}